using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Geekees.Common.Utilities;

namespace Geekees.App.HRAssistant.Web.Common
{
	public class PageBase : System.Web.UI.Page
	{
		protected override void OnInit( EventArgs e )
		{
			base.OnInit( e );

			#region set page title

			string strTitle = Language.GetResource( this.Page.GetType().ToString(), this );
			this.SetTitle( strTitle );

			#endregion
		}

		/// <summary>
		/// Set the title of the page, if the master page contains a literal name lTitle, set the text value of it.
		/// </summary>
		/// <param name="strTitle"></param>
		protected void SetTitle( string strTitle )
		{
			//this.Title = strTitle;
			Literal lTitle = this.Master.FindControl( "lTitle" ) as Literal;
			if( lTitle != null )
				lTitle.Text = strTitle;
		}

		protected override PageStatePersister PageStatePersister
		{
			get
			{
				string viewStateSetting = ConfigurationManager.AppSettings["ViewStateMode"];

				if( string.IsNullOrEmpty( viewStateSetting ) )
					return base.PageStatePersister;

				ViewStateMode viewstateMode = ViewStateMode.Page;

				try
				{
					switch( viewStateSetting.ToLower() )
					{
						case "cache":
							viewstateMode = ViewStateMode.Cache;
							break;
						case "session":
							viewstateMode = ViewStateMode.Session;
							break;
						default:
							viewstateMode = ViewStateMode.Page;
							break;
					}
					return ViewStateFactory.CreateViewState( viewstateMode, this.Page );
				}
				catch
				{
					return base.PageStatePersister;
				}

			}
		}
	}
}
